package com.stork.sms.activity;


import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Spinner;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TableRow.LayoutParams;
import android.widget.TextView;
import android.widget.Toast;

import com.stork.sms.R;
import com.stork.sms.adapter.MarkListPagerAdapter;

public class ExamList extends Activity {
	
	String[] name={"Arun","Anand","Babu","china","Dhivya"};
	
	String[] regno={"500201","500202","500203","500204","500505"};
	String[] date={"5/7/2014","6/7/2014","7/7/2014","8/7/2014","9/7/20146"};
	String[] subject={"Tamil","English","Maths","Science","Social Science"};
	String[] time={"10.00-01.00","10.00-01.00","02.00-05.00","10.00-01.00","02.00-05.00"};
	
	String Selecteditem;
	String[] Colname={"Date","Time","Subject"};
	
	Spinner ExamType;
	TableLayout MarkListTable;
	ViewPager markListViewPager;
	int viewPagerSize=5;
    MarkListPagerAdapter marklistAdapter;
		
	
	@SuppressLint("NewApi")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_exam_list);
		
		ActionBar ab=getActionBar();
		ab.setDisplayHomeAsUpEnabled(true);
		ab.setTitle("ExamList");
		
		ExamType=(Spinner)findViewById(R.id.Exams_list);
		MarkListTable=(TableLayout)findViewById(R.id.TExam_List);
		
		markListViewPager=(ViewPager)findViewById(R.id.viewPager);
		
		marklistAdapter=new MarkListPagerAdapter(ExamList.this, Colname, viewPagerSize);
		markListViewPager.setAdapter(marklistAdapter);
		markListViewPager.setCurrentItem(0);
		
		//MarkListTable();		
		
		ExamType.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> parent, View view,
					int position, long id) {
				// TODO Auto-generated method stub
				 Selecteditem=ExamType
						 .getSelectedItem().toString();
				 MarkListTable.removeAllViews();
				 if(position!=0)
				 {
				Toast.makeText(getApplicationContext(), Selecteditem, Toast.LENGTH_LONG).show();
				
				TableRow Head = (TableRow)LayoutInflater.from(ExamList.this).inflate(R.layout.head1, null);
			    ((TextView)Head.findViewById(R.id.head)).setText(Selecteditem);
			MarkListTable.addView(Head,new TableLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
			
			if(position <5)
			{
			TableRow nr = (TableRow)LayoutInflater.from(ExamList.this).inflate(R.layout.nameregno1, null);
		    ((TextView)nr.findViewById(R.id.name)).setText(name[position]);
		    ((TextView)nr.findViewById(R.id.regno)).setText(regno[position]);
		MarkListTable.addView(nr,new TableLayout.LayoutParams(
                LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
			}
			else
			{
				TableRow nr = (TableRow)LayoutInflater.from(ExamList.this).inflate(R.layout.nameregno1, null);
			    ((TextView)nr.findViewById(R.id.name)).setText(name[0]);
			    ((TextView)nr.findViewById(R.id.regno)).setText(regno[0]);
			MarkListTable.addView(nr,new TableLayout.LayoutParams(
                    LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
			}
				
		for(int i=0;i<5;i++)
		{
		
		TableRow row = (TableRow)LayoutInflater.from(ExamList.this).inflate(R.layout.subjectexam1, null);
	    ((TextView)row.findViewById(R.id.date)).setText(date[i]);
	    ((TextView)row.findViewById(R.id.time)).setText(time[i]);
	    ((TextView)row.findViewById(R.id.subject)).setText(subject[i]);
	    
	    MarkListTable.addView(row,new TableLayout.LayoutParams(
            LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
		
		}
				 }
				
			
			}

			@Override
			public void onNothingSelected(AdapterView<?> parent) {
				// TODO Auto-generated method stub
				
				
			}
		});
		
	
    }

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.mark_list, menu);
		return true;
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub

		switch(item.getItemId())
		{
		
		case android.R.id.home:
			super.onBackPressed();
			return true;
			
		case R.id.action_logout:
			
			Intent logout=new Intent(ExamList.this, Login.class);
			startActivity(logout);
			return true;
			
		case R.id.action_contactus:
			
			Intent contactus=new Intent(ExamList.this, Contactus.class);
			startActivity(contactus);
			return true;
			
		}			
			return super.onOptionsItemSelected(item);
		}

}
